<template>
  <el-form class="-mb-15px" :model="queryParams" ref="queryFormRef" :inline="true" label-width="100px">
    <el-form-item label="企业名称" prop="organizationName">
      <el-input clearable :maxlength="50" v-model="queryParams.organizationName" placeholder="请输入企业名称"
        @keyup.enter="handleQuery" class="!w-200px" />
    </el-form-item>
    <el-form-item label="煤种名称" prop="proName">
      <el-input clearable :maxlength="50" v-model="queryParams.proName" placeholder="请输煤种名称" @keyup.enter="handleQuery"
        class="!w-200px" />
    </el-form-item>
    <el-form-item label="创建时间" prop="orderReceiveTime">
      <el-date-picker v-model="queryParams.orderReceiveTime" format="YYYY-MM-DD HH:mm:ss"
        value-format="YYYY-MM-DD HH:mm:ss" start-placeholder="开始日期" end-placeholder="结束日期" type="datetimerange" />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="handleQuery">搜索</el-button>
      <el-button @click="resetQuery">重置</el-button>
    </el-form-item>
  </el-form>
  <el-table v-loading="loading" :data="list" border stripe :header-cell-style="{ background: '#F3F4F7', color: '#555' }"
    class="pt-12px">
    <el-table-column label="所属企业" align="center" prop="organizationName" min-width="150" fixed="left"
      :show-overflow-tooltip="true" />
    <el-table-column label="煤种名称" align="center" prop="proName" min-width="200" fixed="left"
      :show-overflow-tooltip="true" />
    <el-table-column label="客户名称" align="center" prop="supName" min-width="150" :show-overflow-tooltip="true" />
    <el-table-column label="运单编号" align="center" prop="waybillNo" min-width="200" :show-overflow-tooltip="true" />
    <el-table-column label="车牌号" align="center" prop="carBrand" min-width="150" :show-overflow-tooltip="true" />
    <el-table-column label="司机身份证" align="center" prop="idCard" width="200" :show-overflow-tooltip="true">
    </el-table-column>
    <el-table-column label="司机姓名" align="center" prop="driverName" min-width="100" :show-overflow-tooltip="true" />
    <el-table-column label="毛重" align="center" prop="grossWeight" min-width="100" :show-overflow-tooltip="true" />
    <el-table-column label="皮重" align="center" prop="netWeight" min-width="100" :show-overflow-tooltip="true" />
    <el-table-column label="净重" align="center" prop="totalWeight" min-width="100" :show-overflow-tooltip="true" />
    <el-table-column label="毛重时间" align="center" prop="grossTime" min-width="200" :formatter="dateFormatter"
      :show-overflow-tooltip="true" />
    <el-table-column label="皮重时间" align="center" prop="netTime" min-width="200" :formatter="dateFormatter"
      :show-overflow-tooltip="true" />
    <el-table-column label="运单状态" align="center" prop="status" min-width="150" :show-overflow-tooltip="true">
      <template #default="{row}">
        <span>{{ getDictLabel(DICT_TYPE.PURCHASE_WAYBILL_STATUS, row.status?.toString()) }}</span>
      </template>
    </el-table-column>
    <el-table-column label="货款单价" align="center" prop="endPrice" min-width="100" :show-overflow-tooltip="true" />
    <el-table-column label="创建时间" align="center" prop="orderReceiveTime" :formatter="dateFormatter" min-width="200"
      :show-overflow-tooltip="true" />
    <el-table-column label="矿发净重" align="center" prop="driverWeight" min-width="100" :show-overflow-tooltip="true" />
    <el-table-column label="矿发磅单时间" align="center" prop="billboardTime" min-width="200" :formatter="dateFormatter"
      :show-overflow-tooltip="true" />
    <el-table-column label="运单来源" align="center" prop="platformSource" min-width="150" :show-overflow-tooltip="true">
      <template #default="{row}">
        <span>{{ getDictLabel(DICT_TYPE.PLATFORM_SOURCE, row.platformSource?.toString()) }}</span>
      </template>
    </el-table-column>
  </el-table>
  <Pagination :total="total" v-model:page="queryParams.pageNo" v-model:limit="queryParams.pageSize"
    @pagination="getList" />
</template>
<script setup lang="ts" name="enterpriseManage">
  import * as Utils from '@/utils/dict'
  import { cloneDeep } from 'lodash'
  import * as coalMarket from '@/api/coalMarket'
  import { dateFormatter } from '@/utils/formatTime'

  const { DICT_TYPE, getIntDictOptions, getDictLabel } = reactive(Utils)
  const loading = ref(false) // 列表的加载中
  const total = ref(0) // 列表的总页数
  const list = ref([]) // 列表的数据
  const queryParams = ref({
    pageNo: 1,
    pageSize: 10,
    organizationName: undefined,
    proName: undefined,
    orderReceiveTime: []
  })
  const currentTime = ref()
  const queryFormRef = ref()

  /** 查询列表 */
  const getList = async () => {
    loading.value = true
    try {
      const res = await coalMarket.getPurchasePage(queryParams.value)
      list.value = res.list || []
      total.value = res.total || 0
    } finally {
      loading.value = false
    }
  }

  /** 搜索按钮操作 */
  const handleQuery = () => {
    queryParams.value.pageNo = 1
    getList()
  }

  /** 重置按钮操作 */
  const resetQuery = () => {
    queryFormRef.value.resetFields()
    handleQuery()
  }

  /** 初始化 **/
  onMounted(() => {
    getList()
  })
</script>